<template>
  <u-modal v-model="show" :show-title="false" show-cancel-button mask-close-able @confirm="modalConfirm" @cancel="close">
    <view class=" notice-modal">
      <u-form :model="form" ref="form1">
        <u-form-item label="类型" required>
          <u-input v-model="typeName" disabled />
        </u-form-item>
        <u-form-item label="内容" required><u-input type="textarea" v-model="form.alertName" disabled /></u-form-item>
      </u-form>
    </view>
  </u-modal>
</template>

<script setup>
import { ref } from 'vue'
import { noticeType } from '@/apis/dict.js'
import { orderOutNoticeApi } from '@/apis/orderManagement.js'
const show = ref(false)
const form = ref({
  alertType: "",
  alertName: "",
  outorderid: "",
  company: ""
})
const typeName = ref('')
const open = async (item, type) => {
  const text = type === '1' ? '入库' : '出库'
  form.value.alertName = `订单：${item.id}已完成${text}！`
  const res = await noticeType()
  if (res.data.length > 0) {
    const target = res.data.find(item => item.dictValue === type)
    form.value.alertType = target.dictValue
    typeName.value = target.dictLabel
  }
  show.value = true
  form.value.outorderid = item.id
}
const close = () => {
  show.value = false
}

const modalConfirm = async () => {
  const res = await orderOutNoticeApi(form.value)
  if (res.code === 200) {
    uni.$u.toast("通知成功")
    close()
  }
}

defineExpose({
  open
})
</script>

<style scoped lang="scss">
.notice-modal {
  padding: 20rpx 40rpx;
}
</style>
